package com.lswms.modules.lswms.service.impl.base;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lswms.common.service.impl.CrudServiceImpl;
import com.lswms.modules.lswms.MEGConstant;
import com.lswms.modules.lswms.dao.base.PutawaystrategyDao;
import com.lswms.modules.lswms.dto.base.PutawaystrategyDTO;
import com.lswms.modules.lswms.entity.base.CodeEntity;
import com.lswms.modules.lswms.entity.base.PutawaystrategyEntity;
import com.lswms.modules.lswms.service.base.PutawaystrategyService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 上架策略
 *
 * @author DX sunlightcs@gmail.com
 * @since 1.0.0 2021-06-21
 */
@Service
public class PutawaystrategyServiceImpl extends CrudServiceImpl<PutawaystrategyDao, PutawaystrategyEntity, PutawaystrategyDTO> implements PutawaystrategyService {
	
    @Override
    public QueryWrapper<PutawaystrategyEntity> getWrapper(Map<String, Object> params){
        String id = (String)params.get("id");
        String strategykey = (String)params.get("strategykey");
        String strategyname = (String)params.get("strategyname");

        QueryWrapper<PutawaystrategyEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StringUtils.isNotBlank(id), "id", id);
        wrapper.eq(StringUtils.isNotBlank(strategykey), "strategykey", strategykey);
        wrapper.like(StringUtils.isNotBlank(strategyname), "strategyname", strategyname);

        
        return wrapper;
    }

	@Override
	public String validate(PutawaystrategyDTO dto) {
			String strategyname =dto.getStrategyname() ; 
		
		if( StringUtils.isEmpty(strategyname)) {
			return  String.format(MEGConstant.IS_NOT_EMPTY, "strategyname")  ;
		}
		
		 QueryWrapper<PutawaystrategyEntity> wrapper = new QueryWrapper<>();
		 wrapper.eq("strategyname", strategyname);
		 Integer count = baseDao.selectCount(wrapper);
		 if(count>0) {
			 return  String.format(MEGConstant.VALUE_EXISTS, strategyname )  ;
		 }
		return "";
	}

}